Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git] / 10261 - Ferry loading / 10261.cpp
blobfe374a77b9ed635b69a2ec8a5ea13c09e3320e77
1 #include <iostream>
2 #include <algorithm>
3 #include <climits>
4 #include <vector>
6 using namespace std;
8 int capacity, n;
9 vector<int> w;
11 int dp(int p, int s, int i){
12 if (i >= n)
13 return 0;
15 int ans = -100000;
16 if (p + w[i] <= capacity) ans = max(ans, dp(p + w[i], s, i+1) + 1);
17 if (s + w[i] <= capacity) ans = max(ans, dp(p, s + w[i], i+1) + 1);
19 //cout << p << " " << s << " " << i << " ";
20 //cout << ans << endl;
22 return ans;
25 int main(){
26 int C;
27 cin >> C;
28 while (C--){
29 cin >> capacity;
30 capacity *= 100;
32 w.clear();
33 int x;
34 while(cin >> x && x){
35 w.push_back(x);
38 n = w.size();
40 cout << dp(0,0,0) << endl;
42 return 0;